package com.bluemson.controller;

import com.bluemson.entity.Article;
import com.bluemson.entity.Comment;
import com.bluemson.entity.Plate;
import com.bluemson.entity.User;
import com.bluemson.service.GetService;
import com.bluemson.service.Impl.GetServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mac
 */
@Controller
@RequestMapping("/get")
public class GetController {
    GetService getService = new GetServiceImpl();
    @RequestMapping(value = "/plate", method = {RequestMethod.GET})
    @ResponseBody
    public Map getPlate(){
        List<Plate> plates = getService.getPlate();
        Map map = new HashMap();
        map.put("msg","这是现有板块");
        map.put("plates",plates);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/host", method = {RequestMethod.GET})
    @ResponseBody
    public Map getHost(@RequestParam("name")String name){
        List<String> host = getService.getHost(name);
        Map map = new HashMap();
        map.put("msg","这是该板块的所有版主");
        map.put("hosts",host);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/concernedPlate", method = {RequestMethod.GET})
    @ResponseBody
    public Map getConcernedPlate(@RequestParam("username")String username){
        List<String> plates = getService.getConcernedPlate(username);
        Map map = new HashMap();
        map.put("msg","这是该用户关注的所有板块");
        map.put("plates",plates);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/hostPlate", method = {RequestMethod.GET})
    @ResponseBody
    public Map getHostPlate(@RequestParam("username")String username){
        List<Plate> plates = getService.getHostPlate(username);
        Map map = new HashMap();
        map.put("msg","这是该用户管理的所有板块");
        map.put("plates",plates);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/article", method = {RequestMethod.GET})
    @ResponseBody
    public Map getArticle(){
        List<Article> articles = getService.getArticle();
        Map map= new HashMap();
        map.put("msg","这是所有帖子");
        map.put("articles",articles);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/userArticle", method = {RequestMethod.GET})
    @ResponseBody
    public Map getUserArticle(@RequestParam("username") String username){
        List<Article> articles = getService.getUserArticle(username);
        Map map= new HashMap();
        map.put("msg","这是该用户写的帖子");
        map.put("articles",articles);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/idArticle", method = {RequestMethod.GET})
    @ResponseBody
    public Map getIdArticle(@RequestParam("id")int id){
        Article article = getService.getIdArticle(id);
        Map map= new HashMap();
        map.put("msg","这是该帖子");
        map.put("article",article);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/plateArticle", method = {RequestMethod.GET})
    @ResponseBody
    public Map getPlateArticle(@RequestParam("plate") String plate){
        List<Article> articles = getService.getPlateArticle(plate);
        int[] hostIds = getService.getHostId(plate);
        Map map= new HashMap();
        map.put("msg","这是所有该板块下的帖子");
        map.put("hostIds",hostIds);
        map.put("articles",articles);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/plateHot", method = {RequestMethod.GET})
    @ResponseBody
    public Map getPlateHot(@RequestParam("plate") String plate){
        List<Article> articles = getService.getPlateHot(plate);
        Map map= new HashMap();
        map.put("msg","这是该板块下热门前五的帖子");
        map.put("articles",articles);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/hotArticle", method = {RequestMethod.GET})
    @ResponseBody
    public Map getHotArticle(){
        List<Article> articles = getService.getHotArticle();
        Map map= new HashMap();
        map.put("msg","这是热门前十的帖子");
        map.put("articles",articles);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/allUser", method = {RequestMethod.GET})
    @ResponseBody
    public Map getAllUser(){
        List<User> users = getService.getAllUser();
        Map map= new HashMap();
        map.put("msg","这是所有用户");
        map.put("users",users);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/information", method = {RequestMethod.GET})
    @ResponseBody
    public Map getInformation(@RequestParam("id")int id){
        User user = getService.getInformation(id);
        Map map= new HashMap();
        map.put("msg","这是该用户信息");
        map.put("users",user);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/comment", method = {RequestMethod.GET})
    @ResponseBody
    public Map getComment(@RequestParam("articleId")int id){
        List<Comment> comments = getService.getComment(id);
        Map map= new HashMap();
        map.put("msg","这是该帖子下所有评论");
        map.put("comments",comments);
        map.put("status",1);
        return map;
    }
    @RequestMapping(value = "/reply", method = {RequestMethod.GET})
    @ResponseBody
    public Map getReply(@RequestParam("id")int id){
        List<Comment> comments = getService.getReply(id);
        Map map= new HashMap();
        map.put("msg","这是该评论的所有回复");
        map.put("comments",comments);
        map.put("status",1);
        return map;
    }
}
